﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PSE.LogPackager.Common.Service;

namespace Sinacor.Infra.UI.ErrorLogging
{
    public class ErrorLogger
    {
        public static PSE.Framework.ErrorLogging.LogData WriteLog(PSE.Framework.ErrorLogging.LogType type, Exception ex)
        {
            return WriteClientLog(PSE.Framework.ErrorLogging.ErrorLogger.WriteLog(type, ex));
        }

        public static PSE.Framework.ErrorLogging.LogData WriteLog(PSE.Framework.ErrorLogging.LogType type, string message)
        {
            return WriteClientLog(PSE.Framework.ErrorLogging.ErrorLogger.WriteLog(type, message));
        }

        public static PSE.Framework.ErrorLogging.LogData WriteLog(PSE.Framework.ErrorLogging.LogType type, Exception ex, Dictionary<string, object> extensionData)
        {
            return WriteClientLog(PSE.Framework.ErrorLogging.ErrorLogger.WriteLog(type, ex, extensionData), extensionData);
        }

        public static PSE.Framework.ErrorLogging.LogData WriteLog(PSE.Framework.ErrorLogging.LogType type, string message, Dictionary<string, object> extensionData)
        {
            return WriteClientLog(PSE.Framework.ErrorLogging.ErrorLogger.WriteLog(type, message, extensionData), extensionData);
        }


        private static PSE.Framework.ErrorLogging.LogData WriteClientLog(PSE.Framework.ErrorLogging.LogData logData)
        {
            return WriteClientLog(logData, null);
        }

        private static PSE.Framework.ErrorLogging.LogData WriteClientLog(PSE.Framework.ErrorLogging.LogData logData, Dictionary<string, object> extensionData)
        {
            //try
            //{
            //    if (extensionData == null || !extensionData.ContainsKey("InnerLogData"))
            //    {
            //        LogPackagerServiceClient logPackagerClient = new LogPackagerServiceClient();
            //        logPackagerClient.WriteClientLog(logData);
            //    }
            //}
            //catch (Exception ex)
            //{
            //    PSE.Framework.ErrorLogging.ErrorLogger.WriteLog(PSE.Framework.ErrorLogging.LogType.Error, new Exception("Error sending client log to server.", ex));
            //}

            return logData;
        }
    }
}
